<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script language="javascript" type="text/javascript">
            
            var request = null;
            var request2 = null;

            function createRequest(){
                try{
                    request = new XMLHttpRequest();
                    request2 = new XMLHttpRequest();
                }catch (trymicrosoft){
                    try{
                        request = new ActiveXObject("MsXML2.XMLHTTP");
                        request2 = new ActiveXObject("MsXML2.XMLHTTP");
                    }catch(othermicrosoft){
                        try{
                            request = new ActiveXObject("Microsoft.XMLHTTP");
                            request2 = new ActiveXObject("Microsoft.XMLHTTP");
                        }catch(failed){
                            request = null;
                            request2 = null;
                        }
                    }
                }
                
                if (request == null)
                    alert("Error creating request object!");
                if (request2 == null)
                    alert("Error creating request object!");
            }
            
            function getMessage(){
                createRequest();
                var valoreInput = document.getElementById("campo1").value;
                id=eval(valoreInput);
                
                var url = "http://localhost:8080/WebApplication1/webresources/entity.mumuuser/"+id;
                var url2 = "http://localhost:8080/WebApplication1/webresources/entity.universe/1";
                
                
                request.onreadystatechange = handleResponse;
                request.open("GET", url, true);
                request.send(null);
                
                request2.onreadystatechange = handleResponse2;
                request2.open("GET", url2, true);
                request2.send(null);
            }

            function handleResponse(){
                
   
                if (request.readyState==4 && request.status==200){ 
                    var xmlDocument=request.responseXML;
                    var fnames = xmlDocument.getElementsByTagName("nameSurname");
                    var lnames = xmlDocument.getElementsByTagName("qualification");


                    for(var i=0; i<fnames.length; i++) {
                        var fname = fnames[i].childNodes[0].nodeValue;
                        var lname = lnames[i].childNodes[0].nodeValue;

                        document.getElementById('nomeCognome').value=fname;
                        document.getElementById('qualifica').value=lname;
                    } 
                }
            }
            
            function handleResponse2(){
                
                if (request2.readyState==4 && request2.status==200){ 
                    var xmlDocument=request2.responseXML;
                    var nameUniverse = xmlDocument.getElementsByTagName("description");                    
                    var proprietariUniverso = xmlDocument.getElementsByTagName("idUser");
                    
                    var creatoreUniverso = proprietariUniverso[0].childNodes[0].nodeValue;


                    for(var i=0; i<nameUniverse.length; i++) {
                        if(creatoreUniverso == id){
                            var descUniverse = nameUniverse[i].childNodes[0].nodeValue;
                            document.getElementById('descrizione').value=descUniverse;
                        }else{
                            document.getElementById('descrizione').value="Not Universe";
                        }
                        
                    }
                }
            }
</script>
    </head>
    <body>
        <table>
            <tr>
            <td>Inserisci ID utente : </td>
            <td><input type="text" id="campo1" size="10"/>

            <input type="button" value="Get Details" onclick="getMessage()"/>
            </tr>
            <tr>
            <td>Nome e Cognome : </td>
            <td> <input type="text" id="nomeCognome" size="30"/> </td>
            </tr>

            <tr>
            <td>Qualifica : </td>
            <td> <input type="text" id="qualifica" size="30"/> </td>
            </tr>
            
            <tr>
            <td>Descrizione universo creato : </td>
            <td> <input type="text" id="descrizione" size="40"/> </td>
            </tr>
            
        </table>

    </body>
</html>
